{extend name="../../base/view/common/base" /}
{block name="breadcrumb"}
<span class="layui-breadcrumb">
  <a href="https://www.gougucms.com/" target="_blank">勾股DEV</a>
  <a href="/home/user/setting">信息设置</a>
  <a><cite>修改登录密码</cite></a>
</span>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="main-content">
	{include file="../../base/view/common/submenu" /}
	<div class="main-page-content">
		<form class="layui-form p-4">
			{notempty name="$admin.reg_pwd"}
			<div style="text-align:center; padding:20px 0; font-size:18px; color:#FF5722">初始化密码才能正常使用系统</div>
			{/notempty}
			<h3 class="h3-title">修改登录密码</h3>
			<table class="layui-table layui-table-form">
				<tr>
				  <td class="layui-td-gray-2">旧密码<span style="color: red">*</span></td>
				  <td>
					<input type="password" lay-verify="required" name="old_pwd" placeholder="请输入旧密码" lay-reqText="请输入旧密码" autocomplete="off" class="layui-input">
				  </td>
				  <td class="layui-td-gray-2">用户名</td>
				  <td>{$admin.username}</td>
				</tr>
				<tr>
				  <td class="layui-td-gray-2">新密码 <span style="color: red">*</span></td>
				  <td>
					<input type="password" lay-verify="required" name="pwd" placeholder="请输入新密码" lay-reqText="请输入新密码"  autocomplete="off" class="layui-input">
				  </td>
				  <td class="layui-td-gray-2">确认新密码 <span style="color: red">*</span></td>
				  <td>
					<input type="password" lay-verify="required" name="pwd_confirm" placeholder="请再次输入新密码"  lay-reqText="请再次输入新密码" autocomplete="off" class="layui-input">
				  </td>
				</tr>
			</table>
			<div style="padding: 10px 0">
				<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</form>	
	</div>
</div>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
	var form = layui.form,layer = layui.layer,tool = layui.tool;
    //监听提交
    form.on('submit(webform)', function (data) {
		let callback = function (e) {
			if (e.code == 0) {
				layer.msg('修改密码成功,使用新密码登录');
				//注销
				$.ajax({
					url: "/home/login/login_out.html",
					success: function (e) {
						if (e.code == 0) {
							setTimeout(function () {
								parent.location.href = "/home/login/index.html"
							}, 2000)
						}
					}
				})
			}else{
				layer.msg(e.msg);
			}
		}
		tool.delete("/home/user/edit_password",data.field,callback);
		return false;
    });
  }

</script>
{/block}
<!-- /脚本 -->